package callback

import (
	"bytes"
	"context"
	"encoding/json"
	"net/http"
	"time"

	"servermerge/internal/model"
)

var httpClient = &http.Client{Timeout: 10 * time.Second}

func NotifyMiddle(ctx context.Context, url string, body model.CallbackToMiddle) error {
	b, _ := json.Marshal(body)
	req, _ := http.NewRequestWithContext(ctx, "POST", url, bytes.NewReader(b))
	req.Header.Set("Content-Type", "application/json")
	resp, err := httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	return nil
}
